package org.common.utils.fasttest;

import io.netty.util.concurrent.DefaultThreadFactory;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouzhibing
 * @date 2024/12/17
 */
public class TestFuture {

    public static void test() {
        ExecutorService executorService = Executors.newFixedThreadPool(1, new DefaultThreadFactory("test"));
        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(10_000);
                System.out.println("1 " + Thread.currentThread().getName());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        } , executorService);
        future.whenComplete((result , exception) -> {
            System.out.println("2 " + Thread.currentThread().getName());
        });
    }
}
